package mule;

import static org.junit.Assert.*;

import java.awt.Color;

import org.junit.Test;

public class GambleTest {

	@Test
	public void testGamble() {

		// Test all 5 races
		// flappers start with 1600 money, alien 1, 2, and 3 with 1000 money,
		// and humans with 600 money
		final Player flapper = new Player(1, 1, Color.red, "Balthazaar");
		final Player alien1 = new Player(1, 2, Color.green, "Dennis");
		final Player alien2 = new Player(1, 3, Color.green, "Jackie Chan");
		final Player alien3 = new Player(1, 4, Color.yellow,
				"Jennifer Lawerence");
		final Player human = new Player(1, 5, Color.blue, "Chuck Norris");
		int time;
		int timeBonusMax;
		int roundBonus;

		// Remaining time set between 37 and 50, so time bonus is between 0 and
		// 200
		time = 45;
		timeBonusMax = 200;
		for (int i = 1; i < 13; i++) {
			flapper.setMoney(0);
			alien1.setMoney(0);
			alien2.setMoney(0);
			alien3.setMoney(0);
			human.setMoney(0);

			flapper.gamble(time, i);
			alien1.gamble(time, i);
			alien2.gamble(time, i);
			alien3.gamble(time, i);
			human.gamble(time, i);

			// Total bonus is between the Round bonus and the Round bonus + time
			// bonus
			if (i < 4) {
				// Round between 1 and 3, so Round bonus is 50
				roundBonus = 50;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 8) {
				// Round between 4 and 7, so Round bonus is 100
				roundBonus = 100;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 12) {
				// Round between 8 and 11, so Round bonus is 150
				roundBonus = 150;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else {
				// Round is greater than or equal to 12, so Round bonus is 200
				roundBonus = 200;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			}
		}

		// Remaining time set between 25 and 37, so time bonus is between 0 and
		// 150
		time = 30;
		timeBonusMax = 150;
		for (int i = 1; i < 13; i++) {
			flapper.setMoney(0);
			alien1.setMoney(0);
			alien2.setMoney(0);
			alien3.setMoney(0);
			human.setMoney(0);

			flapper.gamble(time, i);
			alien1.gamble(time, i);
			alien2.gamble(time, i);
			alien3.gamble(time, i);
			human.gamble(time, i);

			// Total bonus is between the Round bonus and the Round bonus + time
			// bonus
			if (i < 4) {
				// Round between 1 and 3, so Round bonus is 50
				roundBonus = 50;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 8) {
				// Round between 4 and 7, so Round bonus is 100
				roundBonus = 100;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 12) {
				// Round between 8 and 11, so Round bonus is 150
				roundBonus = 150;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else {
				// Round is greater than or equal to 12, so Round bonus is 200
				roundBonus = 200;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			}
		}

		// Remaining time set between 12 and 25, so time bonus is between 0 and
		// 100
		time = 20;
		timeBonusMax = 100;
		for (int i = 1; i < 13; i++) {
			flapper.setMoney(0);
			alien1.setMoney(0);
			alien2.setMoney(0);
			alien3.setMoney(0);
			human.setMoney(0);

			flapper.gamble(time, i);
			alien1.gamble(time, i);
			alien2.gamble(time, i);
			alien3.gamble(time, i);
			human.gamble(time, i);

			// Total bonus is between the Round bonus and the Round bonus + time
			// bonus
			if (i < 4) {
				// Round between 1 and 3, so Round bonus is 50
				roundBonus = 50;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 8) {
				// Round between 4 and 7, so Round bonus is 100
				roundBonus = 100;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 12) {
				// Round between 8 and 11, so Round bonus is 150
				roundBonus = 150;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else {
				// Round is greater than or equal to 12, so Round bonus is 200
				roundBonus = 200;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			}
		}

		// Remaining time set between 0 and 12, so time bonus is between 0 and
		// 50
		time = 5;
		timeBonusMax = 50;
		for (int i = 1; i < 13; i++) {
			flapper.setMoney(0);
			alien1.setMoney(0);
			alien2.setMoney(0);
			alien3.setMoney(0);
			human.setMoney(0);

			flapper.gamble(time, i);
			alien1.gamble(time, i);
			alien2.gamble(time, i);
			alien3.gamble(time, i);
			human.gamble(time, i);

			// Total bonus is between the Round bonus and the Round bonus + time
			// bonus
			if (i < 4) {
				// Round between 1 and 3, so Round bonus is 50
				roundBonus = 50;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 8) {
				// Round between 4 and 7, so Round bonus is 100
				roundBonus = 100;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else if (i < 12) {
				// Round between 8 and 11, so Round bonus is 150
				roundBonus = 150;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			} else {
				// Round is greater than or equal to 12, so Round bonus is 200
				roundBonus = 200;
				assertTrue(roundBonus <= flapper.getMoney()
						&& flapper.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien1.getMoney()
						&& alien1.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien2.getMoney()
						&& alien2.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= alien3.getMoney()
						&& alien3.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
				assertTrue(roundBonus <= human.getMoney()
						&& human.getMoney() <= Math.min(250, roundBonus
								+ timeBonusMax));
			}
		}
	}
}